package com.jgp.config;

import com.jgp.common.utils.JGPUtil;
import freemarker.template.TemplateException;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

/**
 * 项目   sys
 * 作者   loufei
 * 时间   2018/2/24
 */
@Order(400)
@Configuration
public class FreeMarkerConfig {

    @Resource
    protected freemarker.template.Configuration configuration;
    
    /*@Resource
    protected FreeMarkerViewResolver resolver;*/

    @PostConstruct
    public void setSharedVariable() {

        //下面三句配置的就是我自己的freemarker的自定义标签，在这里把标签注入到共享变量中去就可以在模板中直接调用了
        //configuration.setSharedVariable("content_list", new ContentListDirective());
        //configuration.setSharedVariable("article_list", new ArticleDirective());
        //configuration.setSharedVariable("channel_list", new ChannelListDirective());
        /**
         * setting配置
         */
        try {
            //resolver.setRequestContextAttribute("request");
            configuration.setSharedVaribles(JGPUtil.freemarkerSharedVaribles());
            configuration.setDateFormat("yyyy/MM/dd");
            configuration.setDateTimeFormat("yyyy-MM-dd HH:mm:ss");
            configuration.setTemplateUpdateDelayMilliseconds(1000);
            configuration.setSetting("default_encoding", "UTF-8");
            configuration.setTagSyntax(freemarker.template.Configuration.AUTO_DETECT_TAG_SYNTAX);
            configuration.setDefaultEncoding("UTF-8");
            configuration.setOutputEncoding("UTF-8");
            configuration.setNumberFormat("#");
            //resolver.setRequestContextAttribute();
            //resolver.setAllowRequestOverride(true);
        } catch (TemplateException e) {
            e.printStackTrace();
        }
    }
  
}
